package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodpropclient.FoodPropManageClient;
import com.woniuxy.food.client.foodpropclient.FoodPropQueryClient;
import com.woniuxy.food.client.foodpropvalueclient.FoodPropValueManageClient;
import com.woniuxy.food.client.foodpropvalueclient.FoodPropValueQueryClient;
import com.woniuxy.food.client.param.InsertFoodPropParam;
import com.woniuxy.food.client.param.InsertFoodPropValueParam;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.FoodPropClient;
import com.woniuxy.store.client.param.foodParam.InsertFoodPropParams;
import com.woniuxy.store.client.param.foodParam.InsertFoodPropValueParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RestController
@RequestMapping("/store/food")
public class FoodPropClientImpl implements FoodPropClient {
    @Autowired
    private FoodPropManageClient foodPropManageClient;
    @Autowired
    private FoodPropQueryClient foodPropQueryClient;
    @Autowired
    private FoodPropValueManageClient foodPropValueManageClient;
    @Autowired
    private FoodPropValueQueryClient foodPropValueQueryClient;

    @Override
    @Log("添加菜品属性")
    public Result insertFoodProp(@Valid InsertFoodPropParams param) {
        InsertFoodPropParam insertFoodPropParam = BeanUtil.toBean(param, InsertFoodPropParam.class);
        insertFoodPropParam.setStoreId(StoreIdUtil.getFromToken());
        return foodPropManageClient.insertFoodProp(insertFoodPropParam);
    }

    @Override
    @Log("删除菜品属性")
    public Result deleteFoodProp(Integer foodPropId) {
        return foodPropManageClient.deleteFoodProp(StoreIdUtil.getFromToken(),foodPropId);
    }

    @Override
    @Log("根据菜品spuID查询全部属性")
    public Result searchFoodPropBySpuId(Integer spuId) {
        return foodPropQueryClient.searchFoodPropBySpuId(StoreIdUtil.getFromToken(),spuId);
    }


    @Override
    @Log("添加菜品属性值")
    public Result insertFoodPropValue(@Valid InsertFoodPropValueParams param) {
        InsertFoodPropValueParam insertFoodPropValueParam = BeanUtil.toBean(param, InsertFoodPropValueParam.class);
        insertFoodPropValueParam.setStoreId(StoreIdUtil.getFromToken());
        return foodPropValueManageClient.insertFoodPropValue(insertFoodPropValueParam);
    }

    @Override
    @Log("删除菜品属性值")
    public Result deleteFoodPropValue(Integer foodPropValueId) {
        return foodPropValueManageClient.deleteFoodPropValue(StoreIdUtil.getFromToken(),foodPropValueId);
    }

    @Override
    @Log("根据菜品属性ID查询全部属性值")
    public Result searchFoodPropValueByFoodPropId(Integer foodPropId) {
        return foodPropValueQueryClient.searchFoodPropValueByFoodPropId(StoreIdUtil.getFromToken(),foodPropId);
    }


}
